//缓存 wx.setStorage(option)/wx.setStorageSync('key', data)/wx.getStorage(option)/wx.getStorageSync('key')

export function getSelectedSchoolId() {
  const schoolID = wx.getStorageSync('schoolId')
  return schoolID || "00000001"
}
export function setSelectedSchoolId(id) {
  wx.setStorageSync('schoolId', id)
}
export function getSelectedSchoolData() {
  const data = wx.getStorageSync('schoolData')
  return data || {}
}
export function setSelectedSchoolData(data) {
  wx.setStorageSync('schoolData', data)
}
export function setSelectedStudentId(id) {
  wx.setStorageSync('sutdentId', id)
}
export function getSelectedStudentId() {
  return wx.getStorageSync('sutdentId')
}
export function getUserId() {
  const userId = wx.getStorageSync('userId')
  return userId || 0
}
export function setUserId(id) {
  wx.setStorageSync('userId', id)
}
export function setOpenId(id) {
  wx.setStorageSync('opendId', id)
}
export function getOpenId() {
  return wx.getStorageSync('opendId') || ""
}

export function getStudentsList() {
  var app = getApp()
  return app.globalData.students
}
export function setStudentsList(students) {
  var app = getApp()
  app.globalData.students = students
}
export function getSchoolList() {
  var app = getApp()
  return app.globalData.schools
}
export function setSchoolList(schools) {
  var app = getApp()
  app.globalData.schools = schools
}
export function getAllGoodsList() {
  var app = getApp()
  return app.globalData.allGoods
}
export function getTouristSchoolId() {
  var app = getApp()
  for (var i = 0; i < app.globalData.schools.length; i++) {
    let item = app.globalData.schools[i]
    if (item.type == 1) {
      return item._id
    };
  }
  return "c550a38464ea064a000009c1183d83f3"
}
export function getCurGoodsInfo(id) {
  var app = getApp()
  for (var item of app.globalData.allGoods) {
    if (item._id == id) {
      return item
    }
  }
  return null
}
export function getRight() {
  var app = getApp()
  return app.globalData.rightId
}
export function setRight(id) {
  var app = getApp()
  app.globalData.rightId = id
}
export function getSizeList(sizeList) {
  let returnSizeList = [];
  sizeList = sizeList.split('|');
  const sizeLists = [
    { id: 1, info: '身高110cm 体重20kg' },
    { id: 2, info: '身高120cm 体重25kg' },
    { id: 3, info: '身高130cm 体重30kg' },
    { id: 4, info: '身高140cm 体重35kg' },
    { id: 5, info: '身高150cm 体重45kg' },
    { id: 6, info: '身高160cm 体重50kg' },
    { id: 7, info: '身高165cm 体重55kg' },
    { id: 8, info: '身高170cm 体重60kg' },
    { id: 9, info: '身高175cm 体重70kg' },
    { id: 10, info: '身高180cm 体重75kg' },
    { id: 11, info: '身高190cm 体重85kg' }
  ]
  sizeList.forEach(item => {
    sizeLists.forEach(node => {
      if (item == node.id)
        returnSizeList.push(node.info)
    })
  })
  return returnSizeList
}
export function getShoesSizeList(sizeList) {
  let returnSizeList = [];
  sizeList = sizeList.split('|');
  const sizeLists = [
    { id: 1, info: '鞋码32' },
    { id: 2, info: '鞋码33' },
    { id: 3, info: '鞋码34' },
    { id: 4, info: '鞋码35' },
    { id: 5, info: '鞋码36' },
    { id: 6, info: '鞋码37' },
    { id: 7, info: '鞋码38' },
    { id: 8, info: '鞋码39' },
    { id: 9, info: '鞋码40' },
    { id: 10, info: '鞋码41' },
    { id: 11, info: '鞋码42' },
    { id: 12, info: '鞋码43' },
    { id: 13, info: '鞋码44' },
    { id: 14, info: '鞋码45' }
  ]
  sizeList.forEach(item => {
    sizeLists.forEach(node => {
      if (item == node.id)
        returnSizeList.push(node.info)
    })
  })
  return returnSizeList
}
export function getUserName() {
  return wx.getStorageSync('userName')
}
export function setUserName(name) {
  wx.setStorageSync('userName', name)
}
export function getUserPhone() {
  return wx.getStorageSync('userPhone')
}
export function setUserPhone(phone) {
  wx.setStorageSync('userPhone', phone)
}
export function getSizeListHeight(sizeList, start = 0) {
  let returnSizeList = [];
  const sizeLists = [
    { id: 1, label: '身高110-120cm' },
    { id: 2, label: '身高120-130cm' },
    { id: 3, label: '身高130-140cm' },
    { id: 4, label: '身高140-150cm' },
    { id: 5, label: '身高150-160cm' },
    { id: 6, label: '身高160-165cm' },
    { id: 7, label: '身高165-170cm' },
    { id: 8, label: '身高170-175cm' },
    { id: 9, label: '身高175-180cm' },
    { id: 10, label: '身高180-190cm' },
    { id: 11, label: '身高190-195cm' }
  ]
  sizeLists.forEach(item => {
    if (start <= item.id && sizeList >= item.id)
      returnSizeList.push(item)
  })
  return returnSizeList
}
export function getSizeListWeight(sizeList, start = 0) {
  let returnSizeList = [];
  const sizeLists = [
    { id: 1, label: '体重20-25kg' },
    { id: 2, label: '体重25-30kg' },
    { id: 3, label: '体重30-35kg' },
    { id: 4, label: '体重35-40kg' },
    { id: 5, label: '体重45-50kg' },
    { id: 6, label: '体重50-55kg' },
    { id: 7, label: '体重55-65kg' },
    { id: 8, label: '体重60-69kg' },
    { id: 9, label: '体重70-75kg' },
    { id: 10, label: '体重75-85kg' },
    { id: 11, label: '体重85-90kg' }
  ]
  sizeLists.forEach(item => {
    if (start <= item.id && sizeList >= item.id)
      returnSizeList.push(item)

  })
  return returnSizeList
}
export function getGradesName(index) {
  console.log(index)
  const gradeList = [
    { id: 0, name: "未定义" },
    { id: 1, name: '星星一班' },
    { id: 2, name: '星星二班' },
    { id: 3, name: '星星三班' },
    { id: 4, name: '月亮一班' },
    { id: 5, name: '月亮二班' },
    { id: 6, name: '月亮三班' },
    { id: 7, name: '太阳一班' },
    { id: 8, name: '太阳二班' },
    { id: 9, name: '太阳三班' },
    { id: 10, name: '小学一年级' },
    { id: 11, name: '小学二年级' },
    { id: 12, name: '小学三年级' },
    { id: 13, name: '小学四年级' },
    { id: 14, name: '小学五年级' },
    { id: 15, name: '小学六年级' },
    { id: 16, name: '初中一年级' },
    { id: 17, name: '初中二年级' },
    { id: 18, name: '初中三年级' },
    { id: 19, name: '高中一年级' },
    { id: 20, name: '高中二年级' },
    { id: 21, name: '高中三年级' },
    { id: 22, name: '大学一年级' },
  ]
  console.log(gradeList[index])
  if (gradeList[index])
    return gradeList[index].name
  return ""
}

export function getAllAddress() {
  var app = getApp()
  return app.globalData.allAdress
}
export function setAllAddress(address) {
  var app = getApp()
  app.globalData.allAdress = address
}

export function getDefaultAddress() {
  var app = getApp()
  return app.globalData.defaultAdress
}
export function setDefaultAddress(address) {
  var app = getApp()
  app.globalData.defaultAdress = address
}
